package com.heiye.blog.ai.factory;

import com.google.common.collect.Maps;
import com.heiye.blog.ai.enums.TextModelTypeEnum;
import com.heiye.blog.ai.strategy.text.TextModelStrategy;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Map;

/**
 * @author: heiye
 * @date: 2025/11/07 下午5:22
 * @version: v1.0.0
 * @description: 文本模型策略工厂
 */
@Configuration
public class TextModelStrategyFactory {

    /**
     * 该处存放所有文本模型策略 --- 自动装配
     */
    @Resource
    private List<TextModelStrategy> textModelStrategies;

    private final Map<TextModelTypeEnum, TextModelStrategy> textModelStrategyMap = Maps.newHashMap();

    /**
     * @PostConstruct： 构造方法执行完成之后执行将 textModelStrategyMap 填充
     */
    @PostConstruct
    public void init() {
        textModelStrategies.forEach(textModelStrategy ->
                textModelStrategyMap.put(textModelStrategy.getTextModelType(), textModelStrategy));
    }

    public TextModelStrategy getStrategy(String textModel) {
        TextModelTypeEnum storageTypeEnum = TextModelTypeEnum.getTextModelType(textModel);
        return textModelStrategyMap.get(storageTypeEnum);
    }

}
